<template>
  <div>
    <div class="action-bar">
      <el-button size="mini" icon="el-icon-download" @click="exportExcel">导出</el-button>
    </div>
  </div>
</template>
<script>
import { getToken } from '@neu/biz-core/utils/auth'
import { formatDate } from '@neu/biz-core/utils/utils'
import { exportReport } from '@neu/dcom-ui/api/operationSupportWeekly'
export default {
  name: 'OperationSupportWeeklyReportActionBar',
  data() {
    return {
      action: '',
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Authentication': getToken()
      },
      fileName: '周报统计导出' + formatDate(new Date())
    }
  },
  methods: {
    // 导出
    exportExcel() {
      exportReport().then(res => {
        const content = res
        const blob = new Blob([content])
        const fileName = this.fileName + '.xlsx'
        // not IE downLoad
        if ('download' in document.createElement('a')) {
          const elink = document.createElement('a')
          elink.download = fileName
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob)
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href)
          document.body.removeChild(elink)
        } else {
          navigator.msSaveBlob(blob, fileName)
        }
      })
    }
  }
}
</script>
